<?php

namespace App\Console\Commands;

use App\Models\Article;
use App\Services\ArticleWeightService;
use Illuminate\Console\Command;

class ArticleWeightCommand extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'article-weight';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Command description';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle()
    {
        \Log::info('-----------start-article-weight-----------------------------');
        Article::chunk(50, function ($list) {
             foreach ($list as $article) {
                 ArticleWeightService::handle($article->id);
             }
        });
        \Log::info('-----------end-article-weight-----------------------------');
    }
}
